package library.Function
{
	
	import flash.filters.BitmapFilterQuality;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	public class GlobalFun
	{
		/*
		返回一个字体描边
		*/
		public static function getBitmapFilter(color:Number = 0x000000,blur:Number = 2,streng:Number = 100,alpha:Number = 0.8,inn:Boolean = false):GlowFilter {
			var alpha:Number = alpha;
			var blurX:Number = blur;
			var blurY:Number = blur;
			var strength:Number = streng;
			var inner:Boolean = inn;
			var knockout:Boolean = false;
			var quality:Number = BitmapFilterQuality.MEDIUM;
			
			return new GlowFilter(color,alpha,blurX,blurY,strength,quality,inner,knockout);
		}
		
		/*
		给一个TextField设置字体格式.
		*/
		
		public static function setTextFormat(txt:TextField,font_:String = "SimSun",Size:int = 16,bold:Boolean = false,
											 color:int = 0x000000,leading:Object = 0,letterSpacing:Object=0,kerning:Object = false):void
		{
			var txtFormat:TextFormat = new TextFormat;
			txtFormat.bold = bold;
			txtFormat.size = Size;
			txtFormat.color = color;
			txtFormat.font = font_;
			txtFormat.leading = leading;
			txtFormat.letterSpacing = letterSpacing;
			txtFormat.kerning = kerning;
			
			txt.setTextFormat(txtFormat);
			txt.defaultTextFormat = txtFormat;
			txt.textColor = color;
			txt.selectable = false;
		}
		
		/*
		返回一个通用的鼠标进入滤镜
		*/
		public static function getEnterColorFilter():ColorMatrixFilter
		{
			var matrix:Array = new Array(1,0,0,0,50,0,1,0,0,50,0,0,1,0,50,0,0,0,1,0);
			return new ColorMatrixFilter(matrix);
		}
		
		/*
		返回一个通用的不可用滤镜
		*/
		public static function getDisColorFilter():ColorMatrixFilter
		{
			var matrix:Array = new Array(1/3, 1/3, 1/3, 0, 0, 1/3, 1/3, 1/3, 0, 0, 1/3, 1/3, 1/3, 0, 0, 0, 0, 0, 1, 0);
			return new ColorMatrixFilter(matrix);
		}
		
		
		/*
		添加一个状态位
		*/
		public static function bitAddState(state:int,pos:int):int
		{
			return state | (1 << (pos - 1));
		}
		/*
		删除一个状态位
		*/
		public static function bitDelState(state:int, pos:int):int
		{
			return state & (~(1 << (pos - 1)));
		}
		
		/*
		检查一个状态位
		*/
		public static function bitCheckState(state:int,pos:int):Boolean
		{
			var b:int = state & 1<< pos - 1;
			var r:Boolean
			if (b)
				r = true;
			else
				r = false;
			return r;
		}
	}
}